<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>我的工作台</title>
    <meta name="keywords" content="低代码">
    <meta name="description" content="低代码">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" href="images/favicon.ico">
    <link rel="stylesheet" href="lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="css/layuimini.css?v=2.0.4.2" media="all">
    <link rel="stylesheet" href="css/themes/default.css" media="all">
    <link href="../editor/assets/drag/js/lib/remixicon/remixicon.css" rel="stylesheet">

    <link rel="stylesheet" href="lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <!--[if lt IE 9]>
    <script src="lib/h5/html5.min.js"></script>
    <script src="lib/h5/respond.min.js"></script>
    <script src="./lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
    <![endif]-->
    <style id="layuimini-bg-color">
    </style>
    <style>
        .mc-page-iframe-content{
            padding: 15px 0 0 15px !important;
            background-color:#f2f2f2;
            box-sizing: border-box;
        }
        .mc-page-iframe-content>.layui-tab-item{

        }

    </style>
</head>
<body class="layui-layout-body layuimini-all">
<div class="layui-layout layui-layout-admin">

    <div class="layui-header header">
        <div class="layui-logo layuimini-logo"></div>



        <div class="layuimini-header-content">
            <a>
                <div class="layuimini-tool"><i title="展开" class="fa fa-outdent" data-side-fold="1"></i></div>
            </a>

            <!--电脑端头部菜单-->
            <ul class="layui-nav layui-layout-left layuimini-header-menu layuimini-menu-header-pc layuimini-pc-show">
            </ul>

            <!--手机端头部菜单-->
            <ul class="layui-nav layui-layout-left layuimini-header-menu layuimini-mobile-show">
                <li class="layui-nav-item">
                    <a href="javascript:;"><i class="fa fa-list-ul"></i> 选择模块</a>
                    <dl class="layui-nav-child layuimini-menu-header-mobile">
                    </dl>
                </li>
            </ul>

            <ul class="layui-nav layui-layout-right">

                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;" data-screenshot="截屏"><i class="layui-icon layui-icon-camera"></i></a>
                </li>
                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;" data-open="新窗口打开"><i class="layui-icon layui-icon-file-b"></i></a>
                </li>
                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;" data-refresh="刷新"><i class="fa fa-refresh"></i></a>
                </li>
                <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;" data-clear="清理" class="layuimini-clear"><i class="fa fa-trash-o"></i></a>
                </li>
                <li class="layui-nav-item mobile layui-hide-xs" lay-unselect>
                    <a href="javascript:;" data-check-screen="full"><i class="fa fa-arrows-alt"></i></a>
                </li>

<!--                当前角色-->
            <!--    <li class="layui-nav-item" lay-unselect>
                    <a href="javascript:;" class="currectLoginRoleName" id="currectLoginRoleName"></a>
                </li>-->

                <li class="layui-nav-item" id="roleNavLi">
                    <a href="javascript:;" id="currectLoginRoleName">切换角色</a>
                    <dl class="layui-nav-child" name="roleNav" id="roleNav"> <!-- 二级菜单 -->
                    </dl>
                </li>
                <div hidden="true">
                    <input type="text" name="roleMenus" id="roleMenus">
                </div>
                <li class="layui-nav-item layuimini-setting">
                    <a href="javascript:;" name="currectLoginUserName" id="currectLoginUserName"></a>
                    <dl class="layui-nav-child">
                        <!--<dd>
                            <a href="javascript:;" layuimini-content-href="page/user-setting.html" data-title="基本资料" data-icon="fa fa-gears">基本资料<span class="layui-badge-dot"></span></a>
                        </dd>-->
                        <!--<dd>
                            <a href="javascript:;" layuimini-content-href="page/user-password.html" data-title="修改密码" data-icon="fa fa-gears">修改密码</a>
                        </dd>-->
                       <!-- <dd>
                            <hr>
                        </dd>-->
                        <dd>
                            <a id="changeInfo" href="javascript:;" class="change-info" data-pid="change-info">修改信息</a>
                        </dd>
                        <dd>
                            <a id="loginOut" href="javascript:;" class="login-out" data-pid="">退出登录</a>
                        </dd>
                    </dl>
                </li>
                <li class="layui-nav-item layuimini-select-bgcolor" lay-unselect>
                    <a href="javascript:;" data-bgcolor="配色方案"><i class="fa fa-ellipsis-v"></i></a>
                </li>
            </ul>
        </div>
    </div>

    <!--无限极左侧菜单-->
    <div class="layui-side layui-bg-black layuimini-menu-left">
    </div>

    <!--初始化加载层-->
    <div class="layuimini-loader">
        <div class="layuimini-loader-inner"></div>
    </div>

    <!--手机端遮罩层-->
    <div class="layuimini-make"></div>

    <!-- 移动导航 -->
    <div class="layuimini-site-mobile"><i class="layui-icon"></i></div>

    <div class="layui-body" style="padding-bottom:20px">

        <div class="layuimini-tab layui-tab-rollTool layui-tab" lay-filter="layuiminiTab" lay-allowclose="true">
            <ul class="layui-tab-title">
                <li class="layui-this" id="layuiminiHomeTabId" lay-id=""></li>
            </ul>
            <div class="layui-tab-control">
                <li class="layuimini-tab-roll-left layui-icon layui-icon-left"></li>
                <li class="layuimini-tab-roll-right layui-icon layui-icon-right"></li>
                <li class="layui-tab-tool layui-icon layui-icon-down">
                    <ul class="layui-nav close-box">
                        <li class="layui-nav-item">
                            <a href="javascript:;"><span class="layui-nav-more"></span></a>
                            <dl class="layui-nav-child">
                                <dd><a href="javascript:;" layuimini-tab-close="current">关 闭 当 前</a></dd>
                                <dd><a href="javascript:;" layuimini-tab-close="other">关 闭 其 他</a></dd>
                                <dd><a href="javascript:;" layuimini-tab-close="all">关 闭 全 部</a></dd>
                            </dl>
                        </li>
                    </ul>
                </li>
            </div>
            <div class="layui-tab-content mc-page-iframe-content">
                <div id="layuiminiHomeTabIframe" class="layui-tab-item layui-show"></div>
            </div>
        </div>

    </div>
</div>
<script src="lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script type="text/javascript" src="./iframe/mc/magicaltool.js"></script>
<script type="text/javascript" src="./js/common.js"></script>

<script>
    layui.use(['jquery', 'layer', 'miniAdmin','miniTongji'], function () {
        window.magicaltool.default.request.interceptors({
            axios:{
                response:function (res){
                    if(res.code==-2){
                        if(typeof localStorage!='undefined'){
                            window.location.href="./login.html?pid="+localStorage.getItem("pid");
                        }else {
                            window.location.href="./login.html?pid=";
                        }
                    }else if(res.code!=0){
                        alert(res.desc);
                    }
                }
            }
        })
        var $ = layui.jquery,
            layer = layui.layer,
            miniAdmin = layui.miniAdmin;

        // 获取项目所有角色
            window.magicaltool.default.request.axios({
                url: '/magical_lowcode/manager/user/info',
                method: 'get',
                param: {},
            }).then(function (res) {
                if(res.code == 0){
                    var dataArr = res.data.otherRoles;
                    if(dataArr && dataArr.length > 0){
                        // 拼接时 需要name转换text 不然切换role方法接受不到参数
                        dataArr = JSON.parse(JSON.stringify(dataArr).replace(/"name"/g,'"text"'))
                        $(dataArr).each(function(i){
                            var str="<dd><a href='javascript:void(0);' rel='external nofollow' onclick='changeRole(this.text)'>"+this.text+"</a></dd>";
                            $("#roleNav").append(str);
                        })
                    }else {
                        $("#roleNavLi").hide()
                    }
                    // 存入dom元素用于查找角色id
                    $("#roleMenus").val(JSON.stringify(dataArr));
                    // 当前用户名称
                    $("#currectLoginUserName").text(res.data.realname||res.data.username);
                    // 当前角色名称
                    if(res.data.currentRole){
                        $("#currectLoginRoleName").text(res.data.currentRole.name);
                    }
                }
            });
        // 获取角色菜单
            window.magicaltool.default.request.axios({
                url: '/magical_lowcode/manager/user/menu',
                method: 'get',
                param: {},
            }).then(function (res) {
                var menuInfo = []
                if(res.code == 0){
                    menuInfo = res.data;
                    // 设置参数 url 以及额外参数 用户信息
                    var options = {
                        iniUrl: "/magical_lowcode/manager/page/get-setting",    // 初始化接口
                        clearUrl: "api/clear.json", // 缓存清理接口
                        urlHashLocation: true,      // 是否打开hash定位
                        bgColorDefault: false,      // 主题默认配置
                        multiModule: true,          // 是否开启多模块
                        menuChildOpen: false,       // 是否默认展开菜单
                        loadingTime: 0,             // 初始化加载时间
                        pageAnim: true,             // iframe窗口动画
                        maxTabNum: 20,              // 最大的tab打开数量
                        menuInfo: menuInfo,               // 角色菜单
                    };
                    // 初始化后台接口
                    miniAdmin.render(options);
                }
            });
        // 切换用户
        window.changeRole = function(roleName) {
            // 根据name从dom元素拿到角色id
            var roleId = '';
            var roleMenus = JSON.parse($("#roleMenus").val());
            for (var i = 0; i < roleMenus.length;i++){
                if (roleMenus[i].text == roleName){
                    roleId = roleMenus[i].uuid;
                }
            }
            if (roleId == ''){
                layer.msg('切换角色失败', function () { });
                return;
            }
            window.magicaltool.default.request.axios({
                method: 'get',
                url: '/magical_lowcode/manager/user/switch-role',
                param: {
                    roleId: roleId,
                }
            }).then(function (res) {
                if (res.code == 0){
                    layer.msg('正在切换角色，请稍后...');
                    new McSysAdminCommon().storeUserInfo(null,res.data.user);
                    window.location.reload();
                }else{
                    layer.msg('切换角色失败', function () { });
                }
            });
        }
        $('.login-out').on("click", function () {
            window.magicaltool.default.request.axios({
                method: 'post',
                url: '/magical_lowcode/manager/web/logout',
                param: {}
            }).then(function (res) {
                if (res.code == 0){
                    if(typeof localStorage!='undefined'){
                        window.location.href="./login.html?pid="+localStorage.getItem("pid");
                    }else {
                        window.location.href="./login.html?pid=";
                    }
                }else{
                    layer.msg('退出登录失败', function () { });
                }
            });
        });
        $('#changeInfo').on("click", function () {

            var html = '\t<form class="layui-form" id="changeUserInfo">\n' +
                '\t\t<div class="layui-form-item">\n' +
                '\t\t\t<label class="layui-form-label">姓名</label>\n' +
                '\t\t\t<div class="layui-input-block">\n' +
                '\t\t\t\t<input name="realname" class="layui-input" type="text" autocomplete="off"/>\n' +
                '\t\t\t</div>\n' +
                '\t\t</div>\n' +
                '\t\t<div class="layui-form-item">\n' +
                '\t\t\t<label class="layui-form-label">原密码</label>\n' +
                '\t\t\t<div class="layui-input-block">\n' +
                '\t\t\t\t<input name="oldPass" class="layui-input" type="password" autocomplete="off"/>\n' +
                '\t\t\t</div>\n' +
                '\t\t</div>\n' +
                '\t\t<div class="layui-form-item">\n' +
                '\t\t\t<label class="layui-form-label">新密码</label>\n' +
                '\t\t\t<div class="layui-input-block">\n' +
                '\t\t\t\t<input name="pass" class="layui-input" type="password" autocomplete="off"/>\n' +
                '\t\t\t</div>\n' +
                '\t\t</div>\n' +
                '\t\t<div class="layui-form-item layui-hide" id="msgParent" style="margin-bottom: 0px">\n' +
                '\t\t\t<label class="layui-form-label"></label>\n' +
                '\t\t\t<div class="layui-input-block" id="errorMsg" style="color:red">\n' +
                '\t\t\t</div>\n' +
                '\t\t</div>\n' +
                '\t</form>'
            layer.open({
                type:0,
                title:['修改信息'],
                content: html,
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    $("#errorMsg").text("")
                    var realname = $("#changeUserInfo").find("[name='realname']").val()
                    var pass = $("#changeUserInfo").find("[name='pass']").val()
                    var oldPass = $("#changeUserInfo").find("[name='oldPass']").val()

                    window.magicaltool.default.request.axios({
                        method: 'post',
                        url: '/magical_lowcode/manager/user/modify-info',
                        param: {
                            realname: realname,
                            password: pass,
                            confirmPassword: oldPass,
                        }
                    }).then(function (res) {
                        if (res.code == 0){
                            layer.msg("修改成功")
                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                            if(realname){
                                $("#currectLoginUserName").text(realname)
                            }
                        }else{
                            $("#msgParent").removeClass("layui-hide")
                            $("#errorMsg").text(res.desc);
                        }
                    })
                },
                btn2: function(index, layero){
                    layer.close(index)
                }
            });
        });
    });

</script>
</body>
</html>
